import { ref } from 'vue'
import { defineStore } from 'pinia'

export const useUserStore = defineStore('user',() => {
    const userInfo = ref({})
    // 设置用户信息
    const setUserInfo = (obj) => {
        userInfo.value = obj
    }
    // 获取用户信息 
    const getUserInfo = () => {
        return userInfo.value
    }
    // 清除用户信息
    const removeUserInfo = () => {
        userInfo.value = {}
    }
    return {
        userInfo,
        setUserInfo,
        getUserInfo,
        removeUserInfo
    }
},{
    persist: {
        storage: {
            setItem(key, value) {
                uni.setStorageSync(key, value)
            },
            getItem(key) {
                return uni.getStorageSync(key)
            }
        }
    }
})